#include "int.h"

static IRQ_Hander_Type irqtable[NUMBER_OF_INT_VECTORS];
static unsigned int irqNesting;

void default_irqhandler(unsigned int giccIar, void* param)
{
    while(1)
    {

    }
}

void system_irqtable_init(void)
{
    int i = 0;

    irqNesting = 0;
    for(i = 0; i < NUMBER_OF_INT_VECTORS; i++)
    {
        irqtable[i].irqhandler = default_irqhandler;
        irqtable[i].userParam = NULL;
    }
}

void int_init(void)
{
    GIC_Init();
    system_irqtable_init();
}


void system_regiser_irqhandler(unsigned int giccIar, IRQ_Handler handler, void* param)
{
    irqtable[giccIar].irqhandler = handler;
    irqtable[giccIar].userParam = param;
}

void system_irqhandler(unsigned int giccIar)
{
    unsigned int intNum = giccIar & 0x3FF;
    if(intNum >= NUMBER_OF_INT_VECTORS)
    {
        return;
    }
    irqNesting++;

    irqtable[intNum].irqhandler(intNum, irqtable[intNum].userParam);

    irqNesting--;
}